package fy.uap.operatorImpl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.LogFactory;

import com.seeyon.oainterface.exportData.form.ValueExport;

import fy.form.listen.operate.AForm_Save_Operator;
import fy.uap.dao.ERPMergerCancelDao;
import fy.util.MyUtil;

public class ERPMergerCancelOperator extends AForm_Save_Operator {
	private static org.apache.commons.logging.Log log = LogFactory
			.getLog(ERPMergerOperator.class);

	private long memberID;
	private List<String> serialList = new ArrayList<String>();
	private String number;

	public String getFormName() {
		return "取消供应商合并申请表（ERP）";
	}

	public boolean save() {
		ProviderMessageManager pmm = new ProviderMessageManager();
		pmm.setMemberID(memberID);
		if (serialList.size() > 0) {

			ERPMergerCancelDao dao = new ERPMergerCancelDao();
			dao.setNumber(number);
			dao.setSerialList(serialList);
			if (dao.save()) {
				if (dao.getWarn() != null) {
					pmm.sendMessage(dao.getWarn());
				}
				return true;
			} else {
				String msg = "【"
						+ super.formBean.getFlowExport().getFlowTitle()
						+ "】写入ERP数据库异常，请联系系统管理员手工导入。";
				pmm.sendMessage(msg);
				log.error(msg);
			}
		} else {
			String msg = "获取【" + super.formBean.getFlowExport().getFlowTitle()
					+ "】的数据异常，无法写入ERP数据库，请联系系统管理员手工导入。";
			pmm.sendMessage(msg);
			log.error(msg);
		}
		return false;
	}

	@Override
	protected void parseOtherField_FirstStep(com.seeyon.v3x.services.flow.bean.FlowExport flowExport) {
		memberID = flowExport.getFlowCreatePerson().getId();

	}

	@Override
	protected void parseValueExport(com.seeyon.v3x.services.form.bean.ValueExport ve) {
		String name = ve.getDisplayName();
		String value = MyUtil.replaceXMLString(ve.getValue());
		if ("序号".equals(name)) {
			if (serialList.indexOf(value) == -1)
				serialList.add(value);
		} else if ("ERP供应商合并申请单单据编号".equals(name)) {
			number = value;
		}
	}
}
